"""
学生接口层
"""
from db import models

#学生注册
def regiter(student_name,student_password):
    #判断学生是否存在
    student_obj = models.Student.self_select(student_name)
    if student_obj:
        return False,"用户已经注册"
    obj = models.Student(student_name,student_password)
    obj.self_save()
    return True,"用户创建成功!"

#学生添加学校
def add_school(school_name,student_dic):
    student_obj = models.Student.self_select(student_dic)
    if student_obj.school:
        return False,"此学生已经选择学校"
    student_obj.add_school(school_name)
    return True,"选课成功!"

#学生添加课程
def add_crouse(crouse_name,student_name):
    student_obj = models.Student.self_select(student_name)
    if crouse_name in student_obj.crouse_list:
        return False,"你已经选择了此课程！"
    student_obj.add_crouse(crouse_name)
    return True,"课程添加成功!"

#查看学生分数
def check_sorce(student_name):
    student_obj = models.Student.self_select(student_name)
    if not student_obj.sorce:
        return False,"该学生没有分数"
    return True,f"该学生分数为{student_obj.sorce}"